package com.amayadream.webchat.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.amayadream.webchat.dao.ILogDao;
import com.amayadream.webchat.pojo.Log;
import com.amayadream.webchat.service.ILogService;
import com.amayadream.webchat.utils.StringUtil;


@Service(value = "logService")
public class LogServiceImpl implements ILogService {
	 @Resource private ILogDao logDao;
	 @Resource private Log log;

	public LogServiceImpl() {
		// TODO 自动生成的构造函数存根
	}

	public List<Log> selectAll(int page, int pageSize) {
		// TODO 自动生成的方法存根
		 return logDao.selectAll(page, pageSize);
	}

	public List<Log> selectLogByUserid(String userid, int page, int pageSize) {
		// TODO 自动生成的方法存根
		 int start = 1;
	        int end = pageSize;
	        if(page != 1) {
	            start = pageSize * (page - 1) + 1;
	            end = pageSize * page;
	        }
	        return logDao.selectLogByUserid(userid, start, end);
	}

	public int selectCount(int pageSize) {
		int pageCount = Integer.parseInt(logDao.selectCount().getUserid());
        return pageCount % pageSize == 0 ? pageCount/pageSize : pageCount/pageSize + 1;
	}

	public int selectCountByUserid(String userid, int pageSize) {
		 int pageCount = Integer.parseInt(logDao.selectCountByUserid(userid).getUserid());
	        return pageCount % pageSize == 0 ? pageCount/pageSize : pageCount/pageSize + 1;
	}

	public boolean insert(Log log) {
		log.setId(StringUtil.getGuid());
        return logDao.insert(log);
	}

	public boolean delete(String id) {
		// TODO 自动生成的方法存根
		 return logDao.delete(id);
	}

	public boolean deleteThisUser(String userid) {
		// TODO 自动生成的方法存根
		 return logDao.deleteThisUser(userid);
	}

	public boolean deleteAll() {
		// TODO 自动生成的方法存根
		 return logDao.deleteAll();
	}

}
